package com.admin.action.bookaction;

import com.admin.Action;
import com.admin.dto.BookListBean;
import com.admin.dto.BookLossBean;
import com.admin.service.bookservice.BookServiceImpl;
import com.admin.service.bookservice.BookServiceInF;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class BookLossAction extends Action {
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {




//         <th>书籍名称</th>
//                <th>价值</th>
//                <th>书籍编号</th>
//                <th>借阅者</th>
//                <th>破损程度</th>
//                <th>借阅者留言</th>



        PrintWriter out=response.getWriter();


        HttpSession session = request.getSession();
//        System.out.println(session.getAttribute("adminInfo"));
        if(session.getAttribute("adminInfo")==null){
            out.println("<script>parent.window.location.href='error.html';</script>");
            return;
        }

        BookServiceInF bookService = new BookServiceImpl();
       List<BookLossBean> beanList= bookService.queryBookDemage();
        System.out.println("书籍损毁表"+beanList);

        Gson gson = new Gson();
        String jsonStr =   gson.toJson(beanList);
        out.print(jsonStr);


    }
}
